package com.wlient.demo.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlient.demo.entity.VoteRecord;
import com.wlient.demo.service.VoteRecordService;
import org.springframework.integration.json.JsonPathUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * (VoteRecord)表控制层
 *
 * @author wlient
 * @since 2022-07-22 14:57:25
 */
@RestController
@RequestMapping("voteRecord")
public class VoteRecordController{
    /**
     * 服务对象
     */
    @Resource
    private VoteRecordService voteRecordService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public VoteRecord selectOne(@PathVariable("id") Long id) {
        return this.voteRecordService.getById(id);
    }

    @GetMapping("/test")
    public void filtter(){
        long beginTime = System.currentTimeMillis();
        List<VoteRecord> record = this.voteRecordService.list(new LambdaQueryWrapper<VoteRecord>().select(VoteRecord::getUserId).orderBy(true,true,VoteRecord::getUserId).last("limit 10"));
        Set<String> collect = record.parallelStream().map(VoteRecord::getUserId).collect(Collectors.toSet());
        long endTime = System.currentTimeMillis();
        System.out.println("使用map方式遍历, 对比耗时: " + (endTime - beginTime)+"毫秒。");
        if ( collect.contains("OI0JsU4rOBoYzM1DVzWP")){
            System.out.println("存在键值");
        }
        System.out.println(collect.size());
    }
}

